#!/bin/sh
##  <%!
##  This file is part of Erlywog.
##
##  Erlywog is free software: you can redistribute it and/or modify
##  it under the terms of the GNU General Public License as published by
##  the Free Software Foundation, either version 3 of the License, or
##  (at your option) any later version.
##
##  Erlywog is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License
##  along with Erlywog.  If not, see <http://www.gnu.org/licenses/>.
##
##  Copyright Jasm Sison 2009 
##  %>
ERLIB=$(erl -noshell -eval 'io:format(code:lib_dir()).' -s erlang halt)
CONFIG_FILE=erlywog-yaws.conf
YAWS_DIR=$(erl -noshell -eval 'io:format(code:lib_dir(yaws)).' -s erlang halt)
if ! test -e .$CONFIG_FILE
then
  if ! test -d $YAWS_DIR
  then
    echo "Error: Please install yaws"
    echo "\t or else change the location in $CONFIG_FILE"
    exit 1
  fi
  if ! test -e ../blog/ebin/blog_controller.beam
  then
    echo "Error: please run make on the directory erlywog/blog."
    echo "Warning: check if the mysql database and tables are installed."
    exit 1
  fi
  cd ..
  sed -e "s@/home/user/erlywog@$PWD@" ./config/erlywog-yaws.conf.tpl > ./config/$CONFIG_FILE
  sed -i "s@/usr/lib/erlang/lib@$ERLIB@" ./config/$CONFIG_FILE
  cd scripts
fi

# run the blog
yaws -i --conf ../config/$CONFIG_FILE --pa ../blog/ebin
